package com.example.index.service.impl;

import com.example.index.entity.CourseinfoStage;
import com.example.index.dao.CourseinfoStageDao;
import com.example.index.service.CourseinfoStageService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 专业课详情阶段(CourseinfoStage)表服务实现类
 *
 * @author makejava
 * @since 2023-08-28 16:05:34
 */
@Service("courseinfoStageService")
public class CourseinfoStageServiceImpl implements CourseinfoStageService {
    @Resource
    private CourseinfoStageDao courseinfoStageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CourseinfoStage queryById(Integer id) {
        return this.courseinfoStageDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param courseinfoStage 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CourseinfoStage> queryByPage(CourseinfoStage courseinfoStage, PageRequest pageRequest) {
        long total = this.courseinfoStageDao.count(courseinfoStage);
        return new PageImpl<>(this.courseinfoStageDao.queryAllByLimit(courseinfoStage, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param courseinfoStage 实例对象
     * @return 实例对象
     */
    @Override
    public CourseinfoStage insert(CourseinfoStage courseinfoStage) {
        this.courseinfoStageDao.insert(courseinfoStage);
        return courseinfoStage;
    }

    /**
     * 修改数据
     *
     * @param courseinfoStage 实例对象
     * @return 实例对象
     */
    @Override
    public CourseinfoStage update(CourseinfoStage courseinfoStage) {
        this.courseinfoStageDao.update(courseinfoStage);
        return this.queryById(courseinfoStage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.courseinfoStageDao.deleteById(id) > 0;
    }
}
